/** this class is the supertype of all the classes that manage entries of an item
 * it stores the values and sets the corresponding new value into the item
 * @author zulianp@lu.unisi.ch & lemmar@lu.unisi.ch
 */

package ch.unisi.inf.projects.java.uom.gui.itemeditor.fieldselector;

import java.awt.Color;
import java.awt.Dimension;

import ch.unisi.inf.projects.java.uom.elements.Item;
import ch.unisi.inf.projects.java.uom.elements.ItemManager;

public abstract class EntryGUI {

	private static Dimension size = new Dimension(120,18);
	protected Item item;
	private static final Color defaultColor = Color.WHITE;
	protected boolean modified;
	protected String key;
	protected String value;
	protected String errorMessage;
	
	protected EntryGUI(final String key, final String value, final Item item)
	{
		this.item = item;
		this.key = key;
		this.value = value;
		this.modified = false;
	}
	
	
	abstract public void select();
	abstract public boolean setFromInput();
	public void save()
	{
		if(modified)
			ItemManager.instance().elementSetField(item, key, value);
	}
	
	public boolean isModified()
	{
		return modified;
	}
	
	public void setModified(final boolean modified)
	{
		this.modified = modified;
	}
	
	public void setValue(final String value)
	{
		this.value = value;
	}
	
	public void setErrorMessage(final String error)
	{
		errorMessage = error;
	}
	
	public String getErrorMessage()
	{
		return errorMessage;
	}
	
	public String getValue ()
	{
		return this.value;
	}
	
	protected Dimension getDefaultSize()
	{
		return size;
	}
	
	protected Color getDefaultColor()
	{
		return defaultColor;
	}
	
	abstract protected void refresh();
}
